var mySwiper = new Swiper(".swiper", {
  autoplay: true, //等同于以下设置
  pagination: {
    //分页器
    el: ".swiper-pagination",
    clickable: true, //点击
  },

  navigation: {
    //前进后退
    nextEl: ".swiper-button-next",
    prevEl: ".swiper-button-prev",
  },

  loop: true, //无限循环
});

/**
 * 点击api-box 改变背景颜色和图片路径
 */

let apiBox = document.querySelectorAll(".api-allbox .api-box");

apiBox.forEach(function (dom, i) {
  dom.addEventListener("mouseover", function () {
    this.style.backgroundColor = "#1271ef";
    this.querySelector("img").src = `../imgs/api0${i + 1}-c.svg`;
  });

  dom.addEventListener("mouseout", function () {
    this.style.backgroundColor = "#fff";
    this.querySelector("img").src = `../imgs/api0${i + 1}.svg`;
  });
});

/**
 * 跑马灯效果
 * 需求:先清除上一个的类名
 *      在给下一个添加类名
 */

/**
 * 获取类名
 *
 */
let busBox = document.querySelectorAll(".bus-box");
let businessBox = document.querySelector(".business-box");

let index = 0;
let timeId = setInterval(foo, 2000);

function foo() {
  // 清除上一个类名
  busBox[index].classList.remove("bus-box-active");

  index++; //序号自增

  if (index === busBox.length) index = 0;

  busBox[index].classList.add("bus-box-active");
}

/**
 * 需求:鼠标移入暂停计时器
 * 移出开启计时器
 */

businessBox.addEventListener("mouseover", function () {
  clearInterval(timeId);
});

businessBox.addEventListener("mouseout", function () {
  timeId = setInterval(foo, 1000);
});

let masterBox = document.querySelector(".master-img  img");
let masterRight = document.querySelectorAll(".master-right li");
let ul = document.querySelector(".master-right  ul");

// masterBox.addEventListener('click',function(){

// })

let reTurn = document.querySelector(".return");
let masterImg = document.querySelector(".master-img img");

window.addEventListener("scroll", function () {
  scrollTop = document.documentElement.scrollTop;

  if (scrollTop > 2000) {
    masterRight.forEach(function (v) {
      v.style.transform = "translateX(0)";
    });

    masterImg.style.transform = `
       rotate(360deg)
       
      `;
  }

  if (scrollTop > 500) {
    reTurn.style.display = "block";
  } else {
    reTurn.style.display = "none";
  }
});

reTurn.addEventListener("click", function () {
  window.scrollTo({
    top:0,
    behavior:"smooth"
  })
});
